package com.example.productiontestble;

import com.example.productiontestble.model.DeviceModel;
import com.example.productiontestble.utils.BluetoothKey;
import com.example.productiontestble.utils.ByteUtils;

public class Resolution {


    public static DeviceModel parseInfo(byte[] packet) {
        DeviceModel device = new DeviceModel();
        byte bt = packet[17];
        device.isDegree = !ByteUtils.getBit(bt, 1);
        device.fanState = (byte) ((ByteUtils.getBit(bt, 2)) ? 0x0 : 0x1);
        device.fan = (ByteUtils.getBit(bt, 3)) ? 0 : 1;
        device.tmpState = (byte) ByteUtils.getBits(bt, 4, 2);
        device.humState = (byte) ByteUtils.getBits(bt, 6, 2);
        device.tmp = ByteUtils.getShort(packet, 19);
        if (device.tmp != BluetoothKey.EMPTY) {
            device.tmp = device.tmp * 10;
        }
        device.hum = (packet[21] & 0xff) * 100;
        bt = packet[18];
        device.autoHighTmpSwitch = !ByteUtils.getBit(bt, 4);
        device.autoLowTmpSwitch = !ByteUtils.getBit(bt, 5);
        device.autoHighHumSwitch = !ByteUtils.getBit(bt, 6);
        device.autoLowHumSwitch = !ByteUtils.getBit(bt, 7);
        if (device.isDegree) {
            device.autoHighTmp = packet[24];
            device.autoLowTmp = packet[25];
        } else {
            device.autoHighTmp = packet[22];
            device.autoLowTmp = packet[23];
        }
        device.autoHighHum = packet[26];
        device.autoLowHum = packet[27];
        device.time = ((packet[28] & 0xff) << 16) + ((packet[29] & 0xff) << 8) + (packet[30] & 0xff);
        return device;
    }

}
